package com.cloud.basic.Schedule;

/**
 * @program: basic
 * @description: 定时任务实现类(业务层)
 * @author: Cloud
 * @create: 2021/5/20 08:45:32
 */
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;


public class QuartzTasks1 implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        System.out.println("QuartzTasks1");
        JobDetail jobDetail = jobExecutionContext.getJobDetail();
        String name = jobDetail.getJobDataMap().getString("name");
        System.out.println("任务执行时间 = " + new Date());
        System.out.println("my job name is  " + name + " at " + new Date());
        Scheduler scheduler = null;
        try {
            scheduler = StdSchedulerFactory.getDefaultScheduler();
            //  停止该定时任务
            scheduler.pauseJob(jobDetail.getKey());
            System.out.println("jobDetail.getKey().getName() = " + jobDetail.getKey().getName());
            boolean b = scheduler.deleteJob(jobDetail.getKey());
            if (b) System.out.println("定时任务已关闭!");
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
